package com.seng.resourcetycoon.factory;

import com.seng.resourcetycoon.core.enums.ResourceType;
import com.seng.resourcetycoon.gui.models.ResourceAttributes;
import com.seng.resourcetycoon.gui.models.ResourceTower;
import com.seng.resourcetycoon.gui.util.TowerNamingHelper;
import com.seng.resourcetycoon.util.AttributeGenerator;
import com.seng.resourcetycoon.util.TowerAttributeGenerator;

import java.math.BigDecimal;

public class TowerFactory {

    private AttributeGenerator attributeGenerator;


    public TowerFactory() {
        this.attributeGenerator = new TowerAttributeGenerator();

    }

    // 新增方法来预生成资源塔的属性
    private ResourceAttributes prepareAttributesForTower(AttributeGenerator attributeGenerator) {
        ResourceType resourceType = attributeGenerator.generateRandomResourceType();
        BigDecimal baseCost = attributeGenerator.getDefaultBuyPrice(resourceType);
        int resourceAmountBase = attributeGenerator.generateRandomCapacity(resourceType);
        double reloadSpeedBase = attributeGenerator.getRandomizedReloadTimeMillis();
        return new ResourceAttributes(TowerNamingHelper.getRandomTowerName(), resourceType, baseCost, resourceAmountBase, reloadSpeedBase);
    }

    public ResourceTower createTower() {
        ResourceAttributes attributes = prepareAttributesForTower(attributeGenerator);
        return new ResourceTower(attributes);
    }

    public AttributeGenerator getAttributeGenerator() {
        return attributeGenerator;
    }

    public void setAttributeGenerator(AttributeGenerator attributeGenerator) {
        this.attributeGenerator = attributeGenerator;
    }

}
